import type { ElementHiderRuleConfig } from '../../../types/constants'
import { PageHandler } from '../../../lib/page_handler'
import { GiteePageType } from '../../../lib/page_handler/platform/gitee/types'
import {
  ElementSelectorPosition,
  ElementSelectorType,
} from '../../../types/constants'
import { ELEMENT_IDENTIFIER_CONFIG } from '../../service/element_identifier/types'
import { addPrefixToConfig } from '../element_config'

export const GITEE_PROJECT_PAGE_ELEMENT_CONFIG: ElementHiderRuleConfig = {
  [ELEMENT_IDENTIFIER_CONFIG.default.headerOne.id]: {
    hide: false,
    selectorType: ElementSelectorType.Complex,
    selector: '#git-header-nav .header-container > a[title=\'企业版\']',
    nameZh: '顶部菜单-企业版',
    position: ElementSelectorPosition.TopLeft,
  },
  [ELEMENT_IDENTIFIER_CONFIG.default.headerTwo.id]: {
    hide: false,
    selectorType: ElementSelectorType.Complex,
    selector: '#git-header-nav .header-container > a[title=\'高校版\']',
    nameZh: '顶部菜单-高校版',
    position: ElementSelectorPosition.TopLeft,
  },
  [ELEMENT_IDENTIFIER_CONFIG.default.headerThree.id]: {
    hide: false,
    selectorType: ElementSelectorType.Complex,
    selector: '#git-header-nav .header-container > a[title=\'私有云\']',
    nameZh: '顶部菜单-私有云',
    position: ElementSelectorPosition.TopLeft,
  },
  [ELEMENT_IDENTIFIER_CONFIG.default.headerFour.id]: {
    hide: false,
    selectorType: ElementSelectorType.Complex,
    selector: '#git-header-nav .header-container > a[title=\'模力方舟\']',
    nameZh: '顶部菜单-模力方舟',
    position: ElementSelectorPosition.TopLeft,
  },
  [ELEMENT_IDENTIFIER_CONFIG.default.headerFive.id]: {
    hide: false,
    selectorType: ElementSelectorType.Complex,
    selector: '#git-header-nav .header-container > a[title=\'AI 队友\']',
    nameZh: '顶部菜单-AI 队友',
    position: ElementSelectorPosition.TopLeft,
  },
  [ELEMENT_IDENTIFIER_CONFIG.default.headerSix.id]: {
    hide: false,
    selectorType: ElementSelectorType.Complex,
    selector: '#git-header-nav .header-container > #my-gitee-dropdown',
    nameZh: '顶部菜单-我的',
    position: ElementSelectorPosition.TopLeft,
  },
  [ELEMENT_IDENTIFIER_CONFIG.default.banner.id]: {
    hide: false,
    selectorType: ElementSelectorType.Class,
    selector: '.fixed-notice-infos',
    position: ElementSelectorPosition.TopCenter,
  },
  [ELEMENT_IDENTIFIER_CONFIG.menu.request.id]: {
    hide: false,
    selectorType: ElementSelectorType.Mix,
    selector: '.git-project-nav .menu a.item:has(.icon-pull-request)',
    nameZh: '项目菜单-拉取请求',
    position: ElementSelectorPosition.MiddleCenter,
  },
  [ELEMENT_IDENTIFIER_CONFIG.menu.wiki.id]: {
    hide: false,
    selectorType: ElementSelectorType.Mix,
    selector: '.git-project-nav .menu a.item:has(.icon-wiki)',
    nameZh: '项目菜单-Wiki',
    position: ElementSelectorPosition.MiddleCenter,
  },
  [ELEMENT_IDENTIFIER_CONFIG.menu.statistics.id]: {
    hide: false,
    selectorType: ElementSelectorType.Mix,
    selector: '.git-project-nav .menu a.item:has(.icon-statistics)',
    nameZh: '项目菜单-统计',
    position: ElementSelectorPosition.MiddleCenter,
  },
  [ELEMENT_IDENTIFIER_CONFIG.menu.workflow.id]: {
    hide: false,
    selectorType: ElementSelectorType.Mix,
    selector: '.git-project-nav .menu a.item:has(.icon-workflow)',
    nameZh: '项目菜单-流水线',
    position: ElementSelectorPosition.MiddleCenter,
  },
  [ELEMENT_IDENTIFIER_CONFIG.menu.services.id]: {
    hide: false,
    selectorType: ElementSelectorType.Mix,
    selector: '.git-project-nav .menu .git-project-service',
    nameZh: '项目菜单-服务',
    position: ElementSelectorPosition.MiddleCenter,
  },
  [ELEMENT_IDENTIFIER_CONFIG.menu.management.id]: {
    hide: false,
    selectorType: ElementSelectorType.Mix,
    selector: '.git-project-nav .menu a.item:has(.icon-settings)',
    nameZh: '项目菜单-管理',
    position: ElementSelectorPosition.MiddleCenter,
  },
  [ELEMENT_IDENTIFIER_CONFIG.ai.aiTool.id]: {
    hide: false,
    selectorType: ElementSelectorType.Mix,
    selector: '#git-readme .ai-readme-dropdown-btn',
    nameZh: 'AI 编辑',
    position: ElementSelectorPosition.MiddleCenter,
    enable: () => {
      const supportPages = [
        GiteePageType.Project,
        GiteePageType.HistoryProject,
      ]
      return supportPages.includes(PageHandler.getCurrentPageType() as GiteePageType)
    },
  },
  [ELEMENT_IDENTIFIER_CONFIG.ai.aiAssistant.id]: {
    hide: false,
    selectorType: ElementSelectorType.Mix,
    selector: '#tree-content-holder .ai-assistant',
    nameZh: 'AI 助手',
    position: ElementSelectorPosition.MiddleCenter,
    enable: () => {
      const supportPages = [
        GiteePageType.CodeView,
      ]
      return supportPages.includes(PageHandler.getCurrentPageType() as GiteePageType)
    },
  },
  [ELEMENT_IDENTIFIER_CONFIG.default.recentActivities.id]: {
    hide: false,
    selectorType: ElementSelectorType.Mix,
    selector: '.project__right-side .side-item.events',
    position: ElementSelectorPosition.MiddleRight,
    enable: () => {
      const supportPages = [
        GiteePageType.Project,
      ]
      return supportPages.includes(PageHandler.getCurrentPageType() as GiteePageType)
    },
  },
  [ELEMENT_IDENTIFIER_CONFIG.default.footer.id]: {
    hide: false,
    selectorType: ElementSelectorType.Tag,
    selector: 'footer',
    position: ElementSelectorPosition.BottomCenter,
  },
  [ELEMENT_IDENTIFIER_CONFIG.default.rightAsideToolbar.id]: {
    hide: false,
    selectorType: ElementSelectorType.Class,
    selector: '.side-toolbar',
    position: ElementSelectorPosition.BottomRight,
  },
}

export const GITEE_COMMIT_PAGE_ELEMENT_CONFIG: ElementHiderRuleConfig = {

}

/**
 * 所有配置
 */
export const GITEE_WEB_ELEMENT_CONFIG: ElementHiderRuleConfig = {
  ...addPrefixToConfig(GITEE_PROJECT_PAGE_ELEMENT_CONFIG, 'project'),
  ...addPrefixToConfig(GITEE_COMMIT_PAGE_ELEMENT_CONFIG, 'commit'),
}
